package com.miracle9.game.util;

import com.miracle9.game.bean.DeskUserSession;
import com.miracle9.game.bean.GameTypeSession;
import com.miracle9.game.bean.UserGameTypeSession;
import com.miracle9.game.enums.GameTypeEnums;
import com.miracle9.game.server.message.*;
import org.apache.mina.core.session.IoSession;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SessionUtils {

    public static List<Set<IoSession>> getAllSession() {
        List<Set<IoSession>> list = new ArrayList<>();
        list.add(LuckSocketHandler.A);
        list.add(FishSocketHandler.x);
        list.add(FishKingSocketHandler.x);
        list.add(CardSocketHandler.w);
        list.add(BulletSocketHandler.v);
        list.add(MermaidSocketHandler.B);
        list.add(LackSocketHandler.z);
        list.add(JoySocketHandler.x);
        list.add(WaterSocketHandler.F);
        list.add(ThousandFishSocketHandler.x);
        list.add(LiKuiFishSocketHandler.x);
        list.add(GoldenCicadaFishSocketHandler.x);
        list.add(BcbmSocketHandler.x);
        list.add(TianGongSocketHandler.x);
        return list;
    }

    public static List<GameTypeSession> getSessionByUserId(int userId) {
        List<GameTypeSession> gameTypeSessionList = new ArrayList<>();
        if (GameParameterAssist.bh.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_0.getType(), LuckSocketHandler.A));
        }
        if (GameParameterAssist.bi.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_1.getType(), FishSocketHandler.x));
        }
        if (GameParameterAssist.bj.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_2.getType(), CardSocketHandler.w));
        }
        if (GameParameterAssist.bk.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_3.getType(), BulletSocketHandler.v));
        }
        if (GameParameterAssist.bl.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_4.getType(), MermaidSocketHandler.B));
        }
        if (GameParameterAssist.aN.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_5.getType(), LackSocketHandler.z));
        }
        if (GameParameterAssist.aP.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_6.getType(), JoySocketHandler.x));
        }
        if (GameParameterAssist.bs.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_7.getType(), WaterSocketHandler.F));
        }
        if (GameParameterAssist.thousandFishGametypeMap.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_9.getType(), ThousandFishSocketHandler.x));
        }
        if (GameParameterAssist.fishKingBi.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_11.getType(), FishKingSocketHandler.x));
        }
        if (GameParameterAssist.likuiFishUserId.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_20.getType(), LiKuiFishSocketHandler.x));
        }
        if (GameParameterAssist.goldenFishUserId.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_37.getType(), GoldenCicadaFishSocketHandler.x));
        }
        if (GameParameterAssist.bcbmUserId.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_52.getType(), BcbmSocketHandler.x));
        }
        if (GameParameterAssist.tgUserId.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_92.getType(), TianGongSocketHandler.x));
        }
        if (GameParameterAssist.lhdUserId.containsKey(userId)) {
            gameTypeSessionList.add(new GameTypeSession(GameTypeEnums.GT_103.getType(), DragonTigerSocketHandler.x));
        }
        return gameTypeSessionList;
    }

    public static List<UserGameTypeSession> getUserGameSession() {
        List<UserGameTypeSession> userGameTypeSessionList = new ArrayList<>();
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.bh, LuckSocketHandler.A));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.bi, FishSocketHandler.x));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.bj, CardSocketHandler.w));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.bk, BulletSocketHandler.v));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.bl, MermaidSocketHandler.B));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.aN, LackSocketHandler.z));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.aP, JoySocketHandler.x));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.bs, WaterSocketHandler.F));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.thousandFishGametypeMap, ThousandFishSocketHandler.x));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.fishKingBi, FishKingSocketHandler.x));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.likuiFishUserId, LiKuiFishSocketHandler.x));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.goldenFishUserId, GoldenCicadaFishSocketHandler.x));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.bcbmUserId, BcbmSocketHandler.x));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.tgUserId, TianGongSocketHandler.x));
        userGameTypeSessionList.add(new UserGameTypeSession(GameParameterAssist.lhdUserId, DragonTigerSocketHandler.x));
        return userGameTypeSessionList;
    }

    public static DeskUserSession getDeskUserSession(int deskId, int gameType) {
        if (GameTypeEnums.GT_0.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.bm.get(deskId), LuckSocketHandler.A);
        }
        if (GameTypeEnums.GT_1.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.bn.get(deskId), FishSocketHandler.x);
        }
        if (GameTypeEnums.GT_2.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.bo.get(deskId), CardSocketHandler.w);
        }
        if (GameTypeEnums.GT_3.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.bp.get(deskId), BulletSocketHandler.v);
        }
        if (GameTypeEnums.GT_4.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.bq.get(deskId), MermaidSocketHandler.B);
        }
        if (GameTypeEnums.GT_5.getType() == gameType) {
            return null;
        }
        if (GameTypeEnums.GT_6.getType() == gameType) {
            return null;
        }
        if (GameTypeEnums.GT_7.getType() == gameType) {
            //return new DeskUserSession(GameParameterAssist.bq.get(deskId), WaterSocketHandler.F);
        }
        if (GameTypeEnums.GT_9.getType() == gameType) {
            return null;
        }
        if (GameTypeEnums.GT_11.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.bn_king.get(deskId), FishKingSocketHandler.x);
        }
        if (GameTypeEnums.GT_20.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.likuiFishUserList.get(deskId), LiKuiFishSocketHandler.x);
        }
        if (GameTypeEnums.GT_37.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.goldenFishUserList.get(deskId), GoldenCicadaFishSocketHandler.x);
        }
        if (GameTypeEnums.GT_42.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.goldSharkUserList.get(deskId), GoldSharkSocketHandler.x);
        }
        if (GameTypeEnums.GT_52.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.bcbmUserList.get(deskId), BcbmSocketHandler.x);
        }
        if (GameTypeEnums.GT_92.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.tgUserList.get(deskId), TianGongSocketHandler.x);
        }
        if (GameTypeEnums.GT_103.getType() == gameType) {
            return new DeskUserSession(GameParameterAssist.lhdUserList.get(deskId), DragonTigerSocketHandler.x);
        }
        return null;
    }

    public static Set<IoSession> getSessionByGameType(int gameType) {
        if (GameTypeEnums.GT_0.getType() == gameType) {
            return LuckSocketHandler.A;
        }
        if (GameTypeEnums.GT_1.getType() == gameType) {
            return FishSocketHandler.x;
        }
        if (GameTypeEnums.GT_2.getType() == gameType) {
            return CardSocketHandler.w;
        }
        if (GameTypeEnums.GT_3.getType() == gameType) {
            return BulletSocketHandler.v;
        }
        if (GameTypeEnums.GT_4.getType() == gameType) {
            return MermaidSocketHandler.B;
        }
        if (GameTypeEnums.GT_5.getType() == gameType) {
            return LackSocketHandler.z;
        }
        if (GameTypeEnums.GT_6.getType() == gameType) {
            return JoySocketHandler.x;
        }
        if (GameTypeEnums.GT_7.getType() == gameType) {
            return WaterSocketHandler.F;
        }
        if (GameTypeEnums.GT_9.getType() == gameType) {
            return ThousandFishSocketHandler.x;
        }
        if (GameTypeEnums.GT_11.getType() == gameType) {
            return FishKingSocketHandler.x;
        }
        if (GameTypeEnums.GT_20.getType() == gameType) {
            return LiKuiFishSocketHandler.x;
        }
        if (GameTypeEnums.GT_37.getType() == gameType) {
            return GoldenCicadaFishSocketHandler.x;
        }
        if (GameTypeEnums.GT_52.getType() == gameType) {
            return BcbmSocketHandler.x;
        }
        if (GameTypeEnums.GT_92.getType() == gameType) {
            return TianGongSocketHandler.x;
        }
        return new HashSet<>();
    }

}
